package model;

import java.util.ArrayList;


public class Stock implements Comparable<Stock> {
	
	private double profit;
	private ArrayList<Double> closePrice;					
	private String stockName;
	
	/**
	 * C'tor to Stock
	 */
	public Stock(double profit,String fileName, ArrayList<Double> closePrice) {			
		this.closePrice = closePrice;
		this.stockName = fileName.substring(0, fileName.lastIndexOf(".csv"));
		this.profit = profit;
	}
	
	
	/**
	 * calculate fitness
	 * @return fitness of this Stock 
	 */
	public double calcProfit(int days) {
		this.profit =  closePrice.get(days) - closePrice.get(0);
		return profit;
	}

	/*---------------Getters && Setters----------------*/
	public ArrayList<Double> getClosePrice() {
		return closePrice;
	}
	public void setClosePrice(ArrayList<Double> geneArr) {
		this.closePrice = geneArr;
	}
	public String getStockName() {
		return stockName;
	}
	public double getProfit() {
		return profit;
	}
	/*---------------Getters && Setters----------------*/
	
	
	/**
	 * Comapare to implements.. order the list from bigger to smaller.
	 */
	public int compareTo(Stock otherChrom) {
		double thisProfit = this.getProfit();
		double otherFitness = otherChrom.getProfit();
		if (thisProfit == otherFitness)
			return 0;
		else if (thisProfit < otherFitness)
			return 1;
		else
			return -1;
	}
		

	private String gene(){
		StringBuilder sb = new StringBuilder();
		for (Double g: closePrice) {				
			sb.append(g);
		}
		return sb.toString();
	}	
	
	@Override
	public String toString(){
		return stockName;
	}
}
